import {
  action,
  observable
} from "mobx-miniprogram";

export const cartStore = observable({
  // 定义仓库模型
  cartList: wx.getStorageSync('cartList') || [],

  addToCart: action(function (payload) {
    const filterList = this.cartList.filter(item => item.proid === payload.proid)
    if (filterList) {
      filterList.num++
    } else {
      this.cartList.push(payload)
    }
  })
})